#ifndef FIFO_H
#define FIFO_H

#include "AReVi/arObject.h"
namespace AReVi {
	class MemoryBlock;
}
using namespace AReVi;

/** A FIFO Stack ... for the network communications */
class FIFO : public ArObject {
public:
	AR_CLASS(FIFO)
	AR_CONSTRUCTOR(FIFO)
	
	/** Get the length of data contained in the stack */
	inline unsigned int getSize() {
		return _length - _offset;
	}

	/** Access to the stack
	 *  Warning : this doesn't unstack */
	char * access();

	/** Append data to the stack */
	bool append(unsigned int size, char *ptr);
	/** Unstack size bytes in the stack */
	bool unstack(unsigned int size);
	/** Unstack size bytes */
	bool extract(unsigned int size, char *ptr);

	/** Retreive a Memory Block of size bytes */
	ArRef<MemoryBlock> extractMB(unsigned int size);

protected:
	/** The memory block containing the data of the stack */
	ArRef<MemoryBlock> _stack;
	
	/** Length of datas */
	unsigned int _length;
	
	/** Offset to the begining of datas */
	unsigned int _offset;
};

#endif
